package cn.jbt.api.admin.config;

import cn.jbt.api.admin.filter.CorsFilter;
import cn.jbt.api.admin.filter.LoginFilter;
import cn.jbt.api.admin.filter.TokenFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    /**
     * <h2>cors filter</h2>
     */
    @Bean
    public FilterRegistrationBean<CorsFilter> registerCorsFilter() {
        FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>();
        bean.setOrder(0);
        bean.setFilter(new CorsFilter());
        bean.addUrlPatterns("/*");
        return bean;
    }

    /**
     * <h2>login filter</h2>
     */
    @Bean
    public FilterRegistrationBean<LoginFilter> registerLoginFilter() {
        FilterRegistrationBean<LoginFilter> bean = new FilterRegistrationBean<>();
        bean.setOrder(1);
        bean.setFilter(new LoginFilter());
        bean.addUrlPatterns("/*");
        return bean;
    }

    /**
     * <h2>token filter</h2>
     */
    @Bean
    public FilterRegistrationBean<TokenFilter> registerTokenFilter() {
        FilterRegistrationBean<TokenFilter> bean = new FilterRegistrationBean<>();
        bean.setOrder(2);
        bean.setFilter(new TokenFilter());
        bean.addUrlPatterns("/*");
        return bean;
    }
}

